/*

 */
package com.ohos.connent.accountcloud.biz.modular.dp.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connent.accountcloud.auth.core.enums.SaClientTypeEnum;
import com.ohos.connent.accountcloud.biz.modular.dp.param.AuthAccountPasswordLoginParam;
import com.ohos.connent.accountcloud.biz.modular.dp.param.AuthGetPhoneValidCodeParam;
import com.ohos.connent.accountcloud.biz.modular.dp.result.DpUserResult;
import com.ohos.connent.accountcloud.biz.modular.dp.service.AuthDpService;
import com.ohos.connent.accountcloud.common.pojo.CommonResult;
import com.ohos.connent.accountcloud.common.util.CommonCryptogramUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * DP平台登录，权限验证等
 *
 **/
@Api(tags = "DP平台登录，权限验证")
@ApiSupport(author = "OHOSCONNECT_TEAM", order = 4)
@RestController
@Validated
@RequestMapping("/api/v1/account/dp/auth")
public class AuthDpController {

    @Autowired
    private AuthDpService authDpService;

    /**
     * 密码加密
     *
     **/
    @ApiOperationSupport(order = 1)
    @ApiOperation("密码加密")
    @GetMapping("/doSm2Encrypt")
    public CommonResult<String> doSm2Encrypt(String password) {
        return CommonResult.data(CommonCryptogramUtil.doSm2Encrypt(password));
    }

    /**
     * B端账号密码登录
     *
     **/
    @ApiOperationSupport(order = 2)
    @ApiOperation("账号密码登录")
    @PostMapping("/doLogin")
    public CommonResult<String> doLogin(@RequestBody @Valid AuthAccountPasswordLoginParam authAccountPasswordLoginParam) {
        return CommonResult.data(authDpService.doLogin(authAccountPasswordLoginParam, SaClientTypeEnum.B.getValue()));
    }

    /**
     * B端退出
     *
     **/
    @ApiOperationSupport(order = 3)
    @ApiOperation("退出")
    @SaCheckLogin
    @GetMapping("/doLogout")
    public CommonResult<String> doLogout() {
        StpUtil.logout();
        return CommonResult.ok();
    }


    /**
     * 获取当前登录用户信息
     *
     **/
    @ApiOperationSupport(order = 4)
    @ApiOperation("获取当前登录用户信息")
    @SaCheckLogin
    @GetMapping("/getLoginUser")
    public CommonResult<DpUserResult> getLoginUser() {
        return CommonResult.data(authDpService.getLoginUser());
    }




    @ApiOperationSupport(order = 5)
    @ApiOperation("获取手机验证码")
    @PostMapping("/getPhoneValidCode")
    public CommonResult<String> getPhoneValidCode(@RequestBody @Valid AuthGetPhoneValidCodeParam authGetPhoneValidCodeParam) {
        return CommonResult.data(authDpService.getPhoneValidCode(authGetPhoneValidCodeParam, SaClientTypeEnum.B.getValue()));
    }
}
